package com.bwie.auth.controller;

import com.bwie.auth.service.AuthService;
import com.bwie.common.domain.Login;
import com.bwie.common.domain.request.LoginRequest;
import com.bwie.common.domain.response.JwtResponse;
import com.bwie.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：Minxiao Hao
 * @Description:
 * @name：AuthController
 * @Date：2024/11/4 10:09
 */
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private AuthService authService;

    /**
     * 确定用户是否存在 或是 手机号与用户 不匹配/////生成验证码
     * @param loginPhone
     * @return
     */
    @PostMapping("/findAuthName/{loginPhone}")
    public Result findAuthName(@PathVariable String loginPhone){
        authService.findAuthName(loginPhone);
        Result result = Result.success();
        return result;
    }

    /**
     * 登录
     * @param loginRequest
     * @return
     */
    @PostMapping("/findAuthPhone")
    public Result<JwtResponse> findAuthPhone(@RequestBody LoginRequest loginRequest){
        JwtResponse jwtResponse = authService.findAuthPhone(loginRequest);
        Result result = Result.success(jwtResponse);
        return result;
    }

    /**
     * 反序列化
     * @return
     */
    @GetMapping("/user/Info")
    public Result findLoginInfo(){
        Login login = authService.findLoginInfo();
        Result result = Result.success(login);
        return result;
    }
}
